# -*- coding: utf-8 -*- 
###############################################################################
# file    : media_info.py
# author  : deng
# date    : Thu Feb 24 15:50:58 2014
# 
# brief   : for media information include formats and streams
# history : init
# modify  : 2014-3-8 media_judge  for video_codec in audio file
#            2014-3-8 get_video_frame_rate  for divided 0
###############################################################################
import os, commands, shutil, sys
import json
from comm_app.utils import *

DEFAULT_AUDIO_FORMAT        = 'mp3'
DEFAULT_AUDIO_CODEC         = 'mp3'
DEFAULT_VIDEO_FORMAT_1      = 'mov,mp4,m4a,3gp,3g2,mj2'
DEFAULT_VIDEO_FORMAT_2      = 'mp4'
DEFAULT_VIDEO_CODEC         = 'h264'
DEFAULT_VIDEO_CODEC_PROFILE_1 = 'constrained baseline'
DEFAULT_VIDEO_CODEC_PROFILE_2 = 'baseline'
DEFAULT_VIDEO_CODEC_PROFILE_3 = 'main'
DEFAULT_VIDEO_AUDIO_CODEC   = 'aac'
MAX_VIDEO_FRAME_RATE        = 30
MIN_VIDEO_FRAME_RATE        = 1
MAX_BIT_RATE                = 800000
MAX_VIDEO_BIT_RATE          = 650000
MAX_VIDEO_AUDIO_BIT_RATE    = 150000
MAX_AUDIO_BIT_RATE          = 330000
MAX_AUDIO_SAMPLE_RATE       = 50000

        
def media_probe(media_src):
    """
    ffprobe获得媒体文件信息，保存到json中
    输入: 媒体文件路径
    输出: 返回生成的json路径
          json与媒体文件同目录，同名，加后缀json
          /opt/22.mp4 -> /opt/22.mp4.json
          如果media_src不存在，会产生一个空的json文件
    """

    #base_media_name = os.path.basename(media_src)
    #(filename, fileext) = os.path.splitext(base_media_name)
    #dir = os.path.dirname(media_src)
    abs_media_src = os.path.abspath(media_src)
    json_dst = '%s.json' % (abs_media_src)
    cmd = 'ffprobe -print_format json -show_format -show_streams -v quiet -i "%s"' % (abs_media_src)
    result = excute_cmd(cmd)
    if not result:
        return '{}'

    return result
    
    
def media_info(str_media):
    """
    解析json，获得媒体的部分信息
    输入: json文件路径
    输出: 返回媒体信息dict
    key                 value(类型: string, 可能为None)        默认值
    filename            媒体文件名(包含路径)
    format_name         媒体格式                               mp4 / mp3
    bit_rate            总比特率                               728000 (Max 950000)
    video_code_name     视频编码器                             h264
    video_width         视频宽度                            
    video_height        视频高度
    video_aspect_ratio  视频宽高比
    video_bit_rate      视频比特率(码流 每秒数据量)            600000 (Max 650000)
    video_frame_rate    视频帧率(fps 每秒帧数)                 25
    audio_codec_name    音频编码器                             aac / mp3
    audio_sample_rate   音频采样率(采样宽度)                   44100 (Max 50000)
    audio_channels      音频通道数(1:单声道 2:立体声)        
    audio_bit_rate      音频比特率                             128000 (Max 300000)
    """

    json_media=json.loads(str_media)

    media_info_dict = dict()
    
    format = json_media.get('format')
    if(format != None):
        nb_streams = format.get('nb_streams')
        media_info_dict['filename'] = format.get('filename')  
        media_info_dict['format_name'] = format.get('format_name')
        media_info_dict['bit_rate'] = format.get('bit_rate')    
        
        streams = json_media.get('streams')
        if(nb_streams != None) and (streams != None):
            for i in range(0, nb_streams):
                codec_type = streams[i].get('codec_type')
                if(codec_type != None) and (codec_type.lower() == 'video'):
                    video_stream = streams[i]  
                    media_info_dict['video_codec_name'] = video_stream.get('codec_name')
                    media_info_dict['video_codec_profile'] = video_stream.get('profile')
                    media_info_dict['video_width'] = str(video_stream.get('width'))
                    media_info_dict['video_height'] = str(video_stream.get('height'))
                    media_info_dict['video_aspect_ratio'] = video_stream.get('display_aspect_ratio')
                    media_info_dict['video_bit_rate'] = video_stream.get('bit_rate') 
                    media_info_dict['video_frame_rate'] = video_stream.get('avg_frame_rate')
                
                if(codec_type != None) and (codec_type.lower() == 'audio'):
                    audio_stream = streams[i]
                    media_info_dict['audio_codec_name'] = audio_stream.get('codec_name')
                    media_info_dict['audio_sample_rate'] = audio_stream.get('sample_rate')
                    media_info_dict['audio_channels'] = str(audio_stream.get('channels'))
                    media_info_dict['audio_bit_rate'] = audio_stream.get('bit_rate')     
            
    return media_info_dict
    
def media_judge(media_info_dict):
    """
    判断媒体信息是否符合规范
    输入: 媒体信息dict
    输出: True or False 
    key               value(类型: string)         
    judge             'pass'：通过                    'fail'：失败，需要转码                
    format_name       'pass'：通过 'None'：不存在     'fail'：不符合规范    
    bit_rate          'pass'：通过 'None'：不存在     'fail'：不符合规范                         
    video_code_name   'pass'：通过 'None'：不存在     'fail'：不符合规范
    video_code_profile    'pass'：通过 'None'：不存在     'fail'：不符合规范         
    video_bit_rate    'pass'：通过 'None'：不存在     'fail'：不符合规范                  
    audio_codec_name  'pass'：通过 'None'：不存在     'fail'：不符合规范                         
    audio_sample_rate 'pass'：通过 'None'：不存在     'fail'：不符合规范                 
    audio_bit_rate    'pass'：通过 'None'：不存在     'fail'：不符合规范                             
    """

    judge_dict = dict()
    judge_dict['judge'] = 'pass'
    judge_dict['format_name'] = 'pass'
    judge_dict['bit_rate'] = 'pass'
    judge_dict['audio_codec_name'] = 'pass'
    judge_dict['audio_sample_rate'] = 'pass'
    judge_dict['audio_bit_rate'] = 'pass'
    judge_dict['video_codec_name'] = 'pass'
    judge_dict['video_codec_profile'] = 'pass'
    judge_dict['video_bit_rate'] = 'pass'
    
    bit_rate = media_info_dict.get('bit_rate')
    if(bit_rate != None):
        if (int(bit_rate) > MAX_BIT_RATE):
            judge_dict['judge'] = 'fail'
            judge_dict['bit_rate'] = 'fail'
    else:
        judge_dict['bit_rate'] = None
        
    audio_sample_rate = media_info_dict.get('audio_sample_rate')
    if(audio_sample_rate != None):
        if (int(audio_sample_rate) > MAX_AUDIO_SAMPLE_RATE):
            judge_dict['judge'] = 'fail'
            judge_dict['audio_sample_rate'] = 'fail'
    else:
        judge_dict['audio_sample_rate'] = None
        
    audio_bit_rate = media_info_dict.get('audio_bit_rate')
    if(audio_bit_rate != None):
        if (int(audio_bit_rate) > MAX_AUDIO_BIT_RATE):
            judge_dict['judge'] = 'fail'
            judge_dict['audio_bit_rate'] = 'fail'
    else:
        judge_dict['audio_bit_rate'] = None
    
    video_bit_rate = media_info_dict.get('video_bit_rate')
    if(video_bit_rate != None): 
        if (int(video_bit_rate) > MAX_VIDEO_BIT_RATE):
            judge_dict['judge'] = 'fail'
            judge_dict['video_bit_rate'] = 'fail'
    else:
        judge_dict['video_bit_rate'] = None
        
    format_name = media_info_dict.get('format_name')
    if(format_name != None):
        if(format_name.lower() == DEFAULT_AUDIO_FORMAT):
            audio_codec_name = media_info_dict.get('audio_codec_name')
            if(audio_codec_name != None):
                if (audio_codec_name.lower() != DEFAULT_AUDIO_CODEC):
                    judge_dict['judge'] = 'fail'
                    judge_dict['audio_codec_name'] = 'fail'
            else:
                judge_dict['audio_codec_name'] = None
    
        else:
            if(format_name.lower() == DEFAULT_VIDEO_FORMAT_1) or (format_name.lower() == DEFAULT_VIDEO_FORMAT_2):
                audio_codec_name = media_info_dict.get('audio_codec_name')
                if(audio_codec_name != None): 
                    if (audio_codec_name.lower() != DEFAULT_VIDEO_AUDIO_CODEC):
                        judge_dict['judge'] = 'fail'
                        judge_dict['audio_codec_name'] = 'fail'
                else:
                    judge_dict['audio_codec_name'] = None
                    
                video_codec_name = media_info_dict.get('video_codec_name')
                if(video_codec_name != None): 
                    if (video_codec_name.lower() != DEFAULT_VIDEO_CODEC):
                        judge_dict['judge'] = 'fail'
                        judge_dict['video_codec_name'] = 'fail'
                else:
                    judge_dict['video_codec_name'] = None
                    
                video_codec_profile = media_info_dict.get('video_codec_profile')
                if(video_codec_profile != None): 
                    if (video_codec_profile.lower() != DEFAULT_VIDEO_CODEC_PROFILE_1
					and video_codec_profile.lower() != DEFAULT_VIDEO_CODEC_PROFILE_2
					and video_codec_profile.lower() != DEFAULT_VIDEO_CODEC_PROFILE_3):
                        judge_dict['judge'] = 'fail'
                        judge_dict['video_codec_profile'] = 'fail'
                else:
                    judge_dict['video_codec_profile'] = None
    
            else:#format 不符合规范
                judge_dict['judge'] = 'fail'
                judge_dict['format_name'] = 'fail'
                    
    else:#format 不存在
        judge_dict['judge'] = 'fail'
        judge_dict['format_name'] = 'fail'
        audio_codec_name = media_info_dict.get('audio_codec_name')
        if(audio_codec_name != None): 
            if (audio_codec_name.lower() != DEFAULT_VIDEO_AUDIO_CODEC) and (audio_codec_name.lower() != DEFAULT_AUDIO_CODEC):
                judge_dict['judge'] = 'fail'
                judge_dict['audio_codec_name'] = 'fail'
        else:
            judge_dict['audio_codec_name'] = None
    
    #for key, value in judge_dict.items():
    #    print key, ':',  value
        
    if(judge_dict.get('judge') != None) and (judge_dict.get('judge') == 'pass'):
        return True
    else:
        return False

def audio_judge(media_info_dict):
    """
    判断音频信息是否符合规范
    输入: 媒体信息dict
    输出: True or False 
        key                    value(类型: string)         
        judge                'pass'：通过 'fail'：失败，需要转码                
        format_name            'pass'：通过 'None'：不存在     'fail'：不符合规范    
        bit_rate            'pass'：通过 'None'：不存在     'fail'：不符合规范                         
        video_code_name        'pass'：通过 'None'：不存在     'fail'：不符合规范    
        video_code_profile    'pass'：通过 'None'：不存在     'fail'：不符合规范     
        video_bit_rate        'pass'：通过 'None'：不存在     'fail'：不符合规范                  
        audio_codec_name    'pass'：通过 'None'：不存在     'fail'：不符合规范                         
        audio_sample_rate    'pass'：通过 'None'：不存在     'fail'：不符合规范                 
        audio_bit_rate        'pass'：通过 'None'：不存在     'fail'：不符合规范                             
    """

    judge_dict = dict()
    judge_dict['judge'] = 'pass'
    judge_dict['format_name'] = 'pass'
    judge_dict['bit_rate'] = 'pass'
    judge_dict['audio_codec_name'] = 'pass'
    judge_dict['audio_sample_rate'] = 'pass'
    judge_dict['audio_bit_rate'] = 'pass'
    judge_dict['video_codec_name'] = 'pass'
    judge_dict['video_codec_profile'] = 'pass'
    judge_dict['video_bit_rate'] = 'pass'
    
    bit_rate = media_info_dict.get('bit_rate')
    if(bit_rate != None):
        if (int(bit_rate) > MAX_BIT_RATE):
            judge_dict['judge'] = 'fail'
            judge_dict['bit_rate'] = 'fail'
    else:
        judge_dict['bit_rate'] = None
        
    audio_sample_rate = media_info_dict.get('audio_sample_rate')
    if(audio_sample_rate != None):
        if (int(audio_sample_rate) > MAX_AUDIO_SAMPLE_RATE):
            judge_dict['judge'] = 'fail'
            judge_dict['audio_sample_rate'] = 'fail'
    else:
        judge_dict['audio_sample_rate'] = None
        
    audio_bit_rate = media_info_dict.get('audio_bit_rate')
    if(audio_bit_rate != None):
        if (int(audio_bit_rate) > MAX_AUDIO_BIT_RATE):
            judge_dict['judge'] = 'fail'
            judge_dict['audio_bit_rate'] = 'fail'
    else:
        judge_dict['audio_bit_rate'] = None
    
    video_bit_rate = media_info_dict.get('video_bit_rate')
    if(video_bit_rate != None): 
        if (int(video_bit_rate) > MAX_VIDEO_BIT_RATE):
            judge_dict['judge'] = 'fail'
            judge_dict['video_bit_rate'] = 'fail'
    else:
        judge_dict['video_bit_rate'] = None
        
    format_name = media_info_dict.get('format_name')
    if(format_name != None):
        if(format_name.lower() == DEFAULT_AUDIO_FORMAT):
            audio_codec_name = media_info_dict.get('audio_codec_name')
            if(audio_codec_name != None):
                if (audio_codec_name.lower() != DEFAULT_AUDIO_CODEC):
                    judge_dict['judge'] = 'fail'
                    judge_dict['audio_codec_name'] = 'fail'
            else:
                judge_dict['audio_codec_name'] = None
        else:#format 不符合规范
            judge_dict['judge'] = 'fail'
            judge_dict['format_name'] = 'fail'
                    
    else:#format 不存在
        judge_dict['judge'] = 'fail'
        judge_dict['format_name'] = 'fail'
        audio_codec_name = media_info_dict.get('audio_codec_name')
        if(audio_codec_name != None): 
            if (audio_codec_name.lower() != DEFAULT_VIDEO_AUDIO_CODEC) and (audio_codec_name.lower() != DEFAULT_AUDIO_CODEC):
                judge_dict['judge'] = 'fail'
                judge_dict['audio_codec_name'] = 'fail'
        else:
            judge_dict['audio_codec_name'] = None
    
    #for key, value in judge_dict.items():
    #    print key, ':',  value
        
    if(judge_dict.get('judge') != None) and (judge_dict.get('judge') == 'pass'):
        return True
    else:
        return False
        
        
def video_judge(media_info_dict):
    """
    判断视频信息是否符合规范
    输入: 媒体信息dict
    输出: True or False 
        key                    value(类型: string)         
        judge                'pass'：通过 'fail'：失败，需要转码                
        format_name            'pass'：通过 'None'：不存在     'fail'：不符合规范    
        bit_rate            'pass'：通过 'None'：不存在     'fail'：不符合规范                         
        video_code_name        'pass'：通过 'None'：不存在     'fail'：不符合规范    
        video_code_profile    'pass'：通过 'None'：不存在     'fail'：不符合规范     
        video_bit_rate        'pass'：通过 'None'：不存在     'fail'：不符合规范                  
        audio_codec_name    'pass'：通过 'None'：不存在     'fail'：不符合规范                         
        audio_sample_rate    'pass'：通过 'None'：不存在     'fail'：不符合规范                 
        audio_bit_rate        'pass'：通过 'None'：不存在     'fail'：不符合规范                             
    """

    judge_dict = dict()
    judge_dict['judge'] = 'pass'
    judge_dict['format_name'] = 'pass'
    judge_dict['bit_rate'] = 'pass'
    judge_dict['audio_codec_name'] = 'pass'
    judge_dict['audio_sample_rate'] = 'pass'
    judge_dict['audio_bit_rate'] = 'pass'
    judge_dict['video_codec_name'] = 'pass'
    judge_dict['video_codec_profile'] = 'pass'
    judge_dict['video_bit_rate'] = 'pass'
    
    bit_rate = media_info_dict.get('bit_rate')
    if(bit_rate != None):
        if (int(bit_rate) > MAX_BIT_RATE):
            judge_dict['judge'] = 'fail'
            judge_dict['bit_rate'] = 'fail'
    else:
        judge_dict['bit_rate'] = None
        
    audio_sample_rate = media_info_dict.get('audio_sample_rate')
    if(audio_sample_rate != None):
        if (int(audio_sample_rate) > MAX_AUDIO_SAMPLE_RATE):
            judge_dict['judge'] = 'fail'
            judge_dict['audio_sample_rate'] = 'fail'
    else:
        judge_dict['audio_sample_rate'] = None
        
    audio_bit_rate = media_info_dict.get('audio_bit_rate')
    if(audio_bit_rate != None):
        if (int(audio_bit_rate) > MAX_AUDIO_BIT_RATE):
            judge_dict['judge'] = 'fail'
            judge_dict['audio_bit_rate'] = 'fail'
    else:
        judge_dict['audio_bit_rate'] = None
        
    video_bit_rate = media_info_dict.get('video_bit_rate')
    if(video_bit_rate != None): 
        if (int(video_bit_rate) > MAX_VIDEO_BIT_RATE):
            judge_dict['judge'] = 'fail'
            judge_dict['video_bit_rate'] = 'fail'
    else:
        judge_dict['video_bit_rate'] = None
        
    format_name = media_info_dict.get('format_name')
    if(format_name != None):
        if(format_name.lower() == DEFAULT_VIDEO_FORMAT_1) or (format_name.lower() == DEFAULT_VIDEO_FORMAT_2):
            audio_codec_name = media_info_dict.get('audio_codec_name')
            if(audio_codec_name != None): 
                if (audio_codec_name.lower() != DEFAULT_VIDEO_AUDIO_CODEC):
                    judge_dict['judge'] = 'fail'
                    judge_dict['audio_codec_name'] = 'fail'
            else:
                judge_dict['audio_codec_name'] = None
                
            video_codec_name = media_info_dict.get('video_codec_name')
            if(video_codec_name != None): 
                if (video_codec_name.lower() != DEFAULT_VIDEO_CODEC):
                    judge_dict['judge'] = 'fail'
                    judge_dict['video_codec_name'] = 'fail'
            else:
                judge_dict['video_codec_name'] = None
                
            video_codec_profile = media_info_dict.get('video_codec_profile')
            if(video_codec_profile != None): 
                if (video_codec_profile.lower() != DEFAULT_VIDEO_CODEC_PROFILE_1
					and video_codec_profile.lower() != DEFAULT_VIDEO_CODEC_PROFILE_2
					and video_codec_profile.lower() != DEFAULT_VIDEO_CODEC_PROFILE_3):
                    judge_dict['judge'] = 'fail'
                    judge_dict['video_codec_profile'] = 'fail'
            else:
                judge_dict['video_codec_profile'] = None

        else:#format 不符合规范
            judge_dict['judge'] = 'fail'
            judge_dict['format_name'] = 'fail'
                    
    else:#format 不存在
        judge_dict['judge'] = 'fail'
        judge_dict['format_name'] = 'fail'
        audio_codec_name = media_info_dict.get('audio_codec_name')
        if(audio_codec_name != None): 
            if (audio_codec_name.lower() != DEFAULT_VIDEO_AUDIO_CODEC) and (audio_codec_name.lower() != DEFAULT_AUDIO_CODEC):
                judge_dict['judge'] = 'fail'
                judge_dict['audio_codec_name'] = 'fail'
        else:
            judge_dict['audio_codec_name'] = None
    
    #for key, value in judge_dict.items():
    #    print key, ':',  value
        
    if(judge_dict.get('judge') != None) and (judge_dict.get('judge') == 'pass'):
        return True
    else:
        return False

def get_media_format(media_info_dict):
    """ 获得媒体格式
    """

    format_name = media_info_dict.get('format_name')
    if (format_name != None):
        return format_name.lower()
    else:
        return None
        

def get_bit_rate(media_info_dict):
    """ 获得总比特率
    """

    bit_rate = media_info_dict.get('bit_rate') 
    if (bit_rate != None):
        int_bit_rate = int(bit_rate)
        return '%d' % (int(int_bit_rate/1000))
    else:
        return None
        

def get_video_codec(media_info_dict):
    """ 获得视频编码器
    """

    video_codec_name = media_info_dict.get('video_codec_name')
    if (video_codec_name != None):
        return video_codec_name.upper()
    else:
        return None
        
def get_video_codec_profile(media_info_dict):
    """ 获取视频 profile
    """

    video_codec_profile = media_info_dict.get('video_codec_profile')
    if (video_codec_profile != None):
        return video_codec_profile
    else:
        return None


def get_audio_codec(media_info_dict):
    """ 获得音频编码器
    """

    audio_codec_name = media_info_dict.get('audio_codec_name')
    if (audio_codec_name != None):
        return audio_codec_name.upper()
    else:
        return None
        

def get_video_resolution(media_info_dict):
    """ 获得视频分辨率 w x h 
    """

    video_width = media_info_dict.get('video_width')
    video_height = media_info_dict.get('video_height')
    if (video_width != None) and (video_height != None):
        return '%sx%s' % (video_width, video_height)
    else:
        return None
        

def get_video_bit_rate(media_info_dict):
    """ 获得视频比特率
    """

    video_bit_rate = media_info_dict.get('video_bit_rate') 
    if (video_bit_rate != None):
        int_video_bit_rate = int(video_bit_rate)
        return '%d' % (int(int_video_bit_rate/1000))
    else:
        return None

        

def get_video_frame_rate(media_info_dict):
    """ 获得视频帧率
    """

    video_frame_rate = media_info_dict.get('video_frame_rate')
    if (video_frame_rate != None) and (video_frame_rate.find('/') > 0):
        num_dem = video_frame_rate.split('/')
        if(len(num_dem) != 2 or (int)(num_dem[1]) == 0):
            return 0
        fps = (int)(num_dem[0]) / (int)(num_dem[1])
        if (fps >= MIN_VIDEO_FRAME_RATE) and (fps <= MAX_VIDEO_FRAME_RATE):
            return fps
        else:
            return 0
    else:
        return None

        
def get_video_aspect_ratio(media_info_dict):
    """ 获得视频宽高比
    """

    video_aspect_ratio = media_info_dict.get('video_aspect_ratio')
    if (video_aspect_ratio != None):
        return video_aspect_ratio
    else:
        return None


def get_audio_bit_rate(media_info_dict):
    """ 获得音频比特率
    """

    audio_bit_rate = media_info_dict.get('audio_bit_rate') 
    if (audio_bit_rate != None):
        int_audio_bit_rate = int(audio_bit_rate)
        return '%d' % (int(int_audio_bit_rate/1000))
    else:
        return None
        

def get_audio_sample_rate(media_info_dict):
    """ 获得音频采样率
    """

    audio_sample_rate = media_info_dict.get('audio_sample_rate') 
    if (audio_sample_rate != None):
        return audio_sample_rate
    else:
        return None

        
def get_audio_channels(media_info_dict):
    """ 获得音频声道数
    """

    audio_channels = media_info_dict.get('audio_channels') 
    if (audio_channels != None):
        if(audio_channels == '1'):
            return 'mono'
        else:
            if(audio_channels == '2'):
                return 'stereo'
            else:
                return 'stereo'
    else:
        return None
    
 
if __name__ == '__main__':
    test_media_src = sys.argv[1]
    #print test_media_src
     
    #解析媒体文件，生成json
    json_src = media_probe(test_media_src)
     
    #print json_src
     
    #解析json，获得媒体信息
    print '\n======================================'
    media_info_dict = media_info(json_src)
    #print media_info_dict

    #根据媒体信息判断，是否需要转码
    print '\n=================media_judge============='
    media_judge(media_info_dict)
    print '===================audio_judge============='
    audio_judge(media_info_dict)
    print '===================video_judge============='
    video_judge(media_info_dict)
     
    #以下获得详细的媒体信息，用于显示，已经做过处理
    print '======================================'
    print u'媒体格式   :    %s' % (get_media_format(media_info_dict))
    print u'总比特率   :    %s' % (get_bit_rate(media_info_dict))
    print u'视频编码器 :    %s' % (get_video_codec(media_info_dict))
    print u'视频profile:    %s' % (get_video_codec_profile(media_info_dict))
    print u'视频比特率 :    %s' % (get_video_bit_rate(media_info_dict))
    print u'视频帧率   :    %s' % (get_video_frame_rate(media_info_dict))
    print u'视频尺寸   :    %s' % (get_video_resolution(media_info_dict))
    print u'视频宽高比 :    %s' % (get_video_aspect_ratio(media_info_dict))
    print u'音频编码器 :    %s' % (get_audio_codec(media_info_dict))
    print u'音频采样率 :    %s' % (get_audio_sample_rate(media_info_dict))
    print u'音频比特率 :    %s' % (get_audio_bit_rate(media_info_dict))
    print u'音频声道   :    %s' % (get_audio_channels(media_info_dict))
    print '======================================'
    
 